<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <input type="text" class="low" placeholder="请输入小写">
    <button>转大写</button>
    <input type="text" class="cap" placeholder="请输入大写">
    <button>转小写</button>
    <br><br>

    <input type="text" name="oldval" id="oldVal" placeholder="请输入字符串">
    <input type="text" name="newval" id="newVal" placeholder="显示转换后的字符串">
    <button onclick="customTransform('upper');">转大写</button>
    <button onclick="customTransform('lower');">转小写</button>
    <script>
        // 字符串大小写转换

        var ipts = document.querySelectorAll('input');
        var btns = document.querySelectorAll('button');
        console.log(ipts);//[input.low, input.cap]
        console.log(btns);// [button, button]

        console.log(ipts[0]);
        btns[0].onclick = function () {
            var str = ipts[0].value;
            str = str.toUpperCase();
            ipts[0].value = str;

            console.log(ipts[0].value);
        }

        console.log(ipts[1]);
        btns[1].onclick = function () {
            var str = ipts[1].value;
            str = str.toLowerCase();
            ipts[1].value = str;

            console.log(ipts[1].value);
        }


        // 字符串大小写转换

        var _oldval = document.getElementById('oldVal'),
            _newval = document.getElementById('newVal');

        // 合并函数
        function customTransform(type) {
            var val = _oldval.value;
            // 方式一
            // if (type == 'upper') {
            //     val = val.toUpperCase();
            // } else if (type == 'lower') {
            //     val = val.toLowerCase();
            // }
            // 方式二
            switch (type) {
                case 'upper':
                    val = val.toUpperCase();
                    break;
                case 'lower':
                    val = val.toLowerCase();
                    break;
                default:
                    break;
            }
            _newval.value = val;
        }



        // 封装函数，求2个数中的最大值
        function getMax() {
            var max = arguments[0];
            for (var i = 1; i <= arguments.length; i++) {
                if (arguments[i] > max) {
                    max = arguments[i];
                }
            }
            return max;
        }
        console.log('3、6中，最大值为：' + getMax(3, 6));
        console.log('3、6、9中，最大值为：' + getMax(3, 6, 9));


        function getMaxNum(a, b, c) {
            a = a || 0;
            b = b || 0;
            c = c || 0;
            return (a - b > 0 ? a : b) - c > 0 ? (a - b > 0 ? a : b) : c;
            // return (a > b ? a : b) > c ? (a > b ? a : b) : c;
        }
        console.log('\'\'、3、4中，最大值为：' + getMaxNum('', 3, 4));
    </script>
</body>

</html>